package com.project.finance.productdetail.controller;

import com.project.finance.common.po.TbProductDetail;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.productdetail.service.ProductDetailService;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/api")
public class ProductDetailController {
    private static final Logger logger = LogManager.getLogger(ProductDetailController.class);
    @Autowired
    private ProductDetailService productDetailService;

    //分页
    @RequestMapping(value = "productDetail",method = RequestMethod.GET)
    public ResultMsg listProductDetailByPageCondition(@RequestParam("pageSize") int pageSize,
                                                      @RequestParam("pageNum") int pageNum){
        ResultMsg resultMsg = productDetailService.listProductDetailByPage(pageSize, pageNum);
        resultMsg.setCode(0);
        return resultMsg;
    }


//    //查询所有理财产品描述信息
//    @RequestMapping(value = "/productDetail",method = RequestMethod.GET)
//    public Result listdetail(){
//        List<TbProductDetail> tbProductDetails = productDetailService.listdetail();
//        return ResultGenerator.apiSuccess(tbProductDetails);
//    }

    //删除理财产品描述信息
    @RequestMapping(value = "productDetail",method = RequestMethod.DELETE)
    public Result delete(@RequestParam("productDetailId")int productdetailid){
        int delete = productDetailService.delete(productdetailid);
        return ResultGenerator.apiSuccess(delete);
    }
//    根据理财产品名称来查询一个产品详情信息
//    @RequestMapping(value = "productdetail",method = RequestMethod.GET)
//    public Result getProoductDetail(@RequestParam("id")int productderailid){
//        logger.info("GET Id : " + productderailid);
//        List<TbProductDetail> tbProductDetails = productDetailService.getProoductDetail(productderailid);
//        Result listResult = ResultGenerator.apiSuccess(tbProductDetails);
//        return listResult;
//    }
}
